﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Transmute.Graphics
{
    public class LinearGradientBrush : GradientBrush
    {
        #region Properties

        private SpriteBatch spriteBatch;

        #endregion

        #region Constructor

        public LinearGradientBrush(int width, int height, Color startColor, Color endColor) : base(GraphicsHelper.GraphicsDevice, width, height, startColor, endColor, new Vector2(width / 2, 0), new Vector2(width / 2, height))
        {
            spriteBatch = GraphicsHelper.SpriteBatch;
            Render();
        }

        #endregion

        #region Methods

        public override void Render()
        {
            GraphicsDevice.SetRenderTarget(this);
            GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin();
                for (var h = 0; h < Height; h++)
                {
                    Color color = Color.Lerp(StartColor, EndColor, (float)((h / GraphicsHelper.GetDistance(StartPoint, EndPoint))));
                    GraphicsHelper.DrawLine(0, h, Width, h, 1, color);
                }
            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);
        }

        #endregion
    }
}
